package com.senior.cas;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * CAS 比较并交换
 */
public class CASDemo {

    public static void main(String[] args) {
        AtomicInteger atomicInteger = new AtomicInteger(10);
        System.out.println(atomicInteger.compareAndSet(10, 2022)+":data"+atomicInteger.get());
        //先进行比较，然后在决定是是否进行交换
        System.out.println(atomicInteger.compareAndSet(10, 2021)+":data"+atomicInteger.get());
    }
}
